//
//  SGSingleton.h
//  SGExtensionObjC
//
//  Created by xyanl on 2025/9/10.
//
//  单例宏的创建
#ifndef SGSingleton_h
#define SGSingleton_h

// .h 文件 @interface 内
#define sgSingletonH(className) \
+ (className *)shared; \
+ (instancetype)new NS_UNAVAILABLE; \
- (instancetype)copy NS_UNAVAILABLE; \
- (instancetype)mutableCopy NS_UNAVAILABLE;

// .m 文件 @implementation 内
#define sgSingletonM(className) \
+ (className *)shared { \
    static className *sharedInstance = nil; \
    static dispatch_once_t onceToken; \
    dispatch_once(&onceToken, ^{ \
        sharedInstance = [[super allocWithZone:NULL] init]; \
    }); \
    return sharedInstance; \
} \
+ (instancetype)allocWithZone:(struct _NSZone *)zone { \
    return [self shared]; \
}

#endif /* SGSingleton_h */
